#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "Q1mi"
# Date: 2018/10/23
import matplotlib.pyplot as plt
nums = [1, 2, 3, 2, 4, 5, 4, 3, 2, 1, 8, 9, 10, 11, 10, 9, 8]
peaks = []
troughs = []
for idx in range(1, len(nums) - 1):
    if nums[idx - 1] < nums[idx] > nums[idx + 1]:
        peaks.append((idx, nums[idx]))
    if nums[idx - 1] > nums[idx] < nums[idx + 1]:
        troughs.append((idx, nums[idx]))

print(peaks)  # [(2, 3), (5, 5), (13, 11)]
print(troughs)  # [(3, 2), (9, 1)]


plt.xticks(rotation=45)
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.plot(range(len(nums)), nums, 'bo-', label="最高温")  # 蓝色--较好
plt.legend()  # 显示图中的标签
plt.xlabel("时间")
plt.ylabel('温度')
plt.show()